package com.abysscore.yachtdesign;
import java.awt.MenuItem;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.MenuElement;


import com.abysscore.yachtdesign.view.FreeShipFrame;
import com.abysscore.yachtdesign.view.FreeShipMenuBar;
import com.apple.laf.*;
import com.apple.eawt.*;

public class Yachtdesign {

	private JFrame mainFrame;
	private static final String APP_NAME="FreeShip Java";
	private FreeShipMenuBar menuBar;
	private FreeShipController control;
	private static ImageIcon appIcon;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.setProperty("com.apple.mrj.application.apple.menu.about.name", APP_NAME);
		// load application icon
		appIcon = new ImageIcon("res/app.png");
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String lcOSName = System.getProperty("os.name").toLowerCase();
		boolean IS_MAC = lcOSName.startsWith("mac os x");
		if (IS_MAC)
		{
			System.out.println("Mac OS X");
			
			System.setProperty("apple.laf.useScreenMenuBar", "true");
			System.setProperty("program.name", APP_NAME);
			new Yachtdesign();
			
		}
		
		// Set shortcuts pltform neutral
		//fileSaveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

	}

	public Yachtdesign()
	{
	    // set some mac-specific properties
	    System.setProperty("apple.awt.graphics.EnableQ2DX", "true");
	    System.setProperty("apple.laf.useScreenMenuBar", "true");
	    control = new FreeShipController();
	    // create an instance of the Mac Application class, so i can handle the 
	    // mac quit event with the Mac ApplicationAdapter
	    Application macApplication = Application.getApplication();
	    FreeShipOSXAdapter macAdapter = new FreeShipOSXAdapter(this);
	    macApplication.addApplicationListener(macAdapter);
	    
	    // need to enable the preferences option manually
	    macApplication.setEnabledPreferencesMenu(true);

	    // set application icon
	    macApplication.setDockIconImage(appIcon.getImage());
	    
	    // display the jframe
	    SwingUtilities.invokeLater(new Runnable()
	    {
	      public void run()
	      {
	        mainFrame = new FreeShipFrame();
	        menuBar = new FreeShipMenuBar(control, mainFrame);
	        mainFrame.pack();
	        mainFrame.setVisible(true);
	      }
	    });
	  }

	  public void handleQuitEvent(ApplicationEvent e)
	  {
	    System.exit(0);
	  }
	  
}
